package framework.utils.random;




public class RandomNumberGenerator {

	//coefficients for the linear congruential generator
	public static final int m = 35;
	public static final int c = 7;
	public static final int a = 31;
	
	static RandomNumberGenerator self;
	static RandomNumber number;
	
	protected RandomNumberGenerator(RandomNumber random){
		number = random;
	}
	
	public static RandomNumberGenerator getInstance(RandomNumber random){
		if(self == null)
			self = new RandomNumberGenerator(random);
		number = random;
		return self;
	}
	
	// Method that implements the linear congruential generator
	//     x[n+1] = (a*x[n] + c) mod m
	public int generate(){
		int rand;
		
		number.x[1]= (a*number.x[0]+c)%m;
		number.x[1]+= (int)Math.floor(Math.random()*20);
		rand = number.x[1]%number.n;
		number.x[0]= number.x[1];
		if (rand == number.last_rand)
			return generate();
		number.last_rand = rand;
		return rand;
	}
}